//
//  SkillCategoryPicker.m
//  APJ Resource
//
//  Created by Richard Zhao on 2/12/14.
//  Copyright (c) 2014 APJ. All rights reserved.
//

#import "SkillCategoryPicker.h"
#import "HRStore.h"
#import "SkillCategory.h"
#import "SkillPicker.h"

@interface SkillCategoryPicker ()
{
    NSArray *dataSource;
}
@end

@implementation SkillCategoryPicker;
@synthesize popView, selectedSkills;

- (id)initWithStyle:(UITableViewStyle)style
{
    self = [super initWithStyle:style];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];

    dataSource = [[HRStore sharedStore] allSkillCategory];
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return dataSource.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"SkillCategoryCell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    
    if (!cell)
    {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
                                      reuseIdentifier:CellIdentifier];
    }
    
    SkillCategory *category = (SkillCategory *)[dataSource objectAtIndex:[indexPath row]];
    cell.textLabel.text = category.skillCategoryCode;
    [cell setAccessoryType:UITableViewCellAccessoryDetailDisclosureButton];
    
    
    return cell;
}

#pragma mark - Table view delegate

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSString *category = [[[tableView cellForRowAtIndexPath:indexPath] textLabel] text];
    SkillPicker *skillView = [[SkillPicker alloc] init];
    [skillView setSelectedSkills:selectedSkills];
    [skillView setSkillCategory:category];
    [[self navigationController] pushViewController:skillView animated:YES];
}

@end
